package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.UserGerenxinxi;
import com.ruoyi.system.service.IUserGerenxinxiService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 个人信息Controller
 * 
 * @author dy
 * @date 2024-05-27
 */
@Controller
@RequestMapping("/system/gerenxinxi")
public class UserGerenxinxiController extends BaseController
{
    private String prefix = "system/gerenxinxi";

    @Autowired
    private IUserGerenxinxiService userGerenxinxiService;

    @RequiresPermissions("system:gerenxinxi:view")
    @GetMapping()
    public String gerenxinxi()
    {
        return prefix + "/gerenxinxi";
    }

    /**
     * 查询个人信息列表
     */
    @RequiresPermissions("system:gerenxinxi:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(UserGerenxinxi userGerenxinxi)
    {
        startPage();
        List<UserGerenxinxi> list = userGerenxinxiService.selectUserGerenxinxiList(userGerenxinxi);
        return getDataTable(list);
    }

    /**
     * 导出个人信息列表
     */
    @RequiresPermissions("system:gerenxinxi:export")
    @Log(title = "个人信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UserGerenxinxi userGerenxinxi)
    {
        List<UserGerenxinxi> list = userGerenxinxiService.selectUserGerenxinxiList(userGerenxinxi);
        ExcelUtil<UserGerenxinxi> util = new ExcelUtil<UserGerenxinxi>(UserGerenxinxi.class);
        return util.exportExcel(list, "个人信息数据");
    }

    /**
     * 新增个人信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存个人信息
     */
    @RequiresPermissions("system:gerenxinxi:add")
    @Log(title = "个人信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(UserGerenxinxi userGerenxinxi)
    {
        return toAjax(userGerenxinxiService.insertUserGerenxinxi(userGerenxinxi));
    }

    /**
     * 修改个人信息
     */
    @RequiresPermissions("system:gerenxinxi:edit")
    @GetMapping("/edit/{userId}")
    public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
    {
        UserGerenxinxi userGerenxinxi = userGerenxinxiService.selectUserGerenxinxiByUserId(userId);
        mmap.put("userGerenxinxi", userGerenxinxi);
        return prefix + "/edit";
    }

    /**
     * 修改保存个人信息
     */
    @RequiresPermissions("system:gerenxinxi:edit")
    @Log(title = "个人信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(UserGerenxinxi userGerenxinxi)
    {
        return toAjax(userGerenxinxiService.updateUserGerenxinxi(userGerenxinxi));
    }

    /**
     * 删除个人信息
     */
    @RequiresPermissions("system:gerenxinxi:remove")
    @Log(title = "个人信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(userGerenxinxiService.deleteUserGerenxinxiByUserIds(ids));
    }
}
